// @ts-ignore
/* eslint-disable */
import * as service from '@/services/sys/sysRoleService';

export interface ModelType {
  namespace: string;
  state: Object;
  effects: {
    query: any;
  };
  reducers: {
    // 启用 immer 之后
    save: any;
  };
  subscriptions: { setup: any };
}

const IndexModel: ModelType = {
  namespace: 'role',

  state: {
    name: '',
  },

  effects: {
    * getMyList({payload, callback}: any, {call}: any) {
    const response = yield call(service.getMyList, payload);
    if (callback) {
      callback(response)
    }
  },
    * findList({payload, callback}: any, {call}: any) {
      const response = yield call(service.findList, payload);
      if (callback) {
        callback(response)
      }
    },
    * saveObject({payload, callback}: any, {call}: any) {
      const response = yield call(service.saveObject, payload);
      if (callback) {
        callback(response)
      }
    },
    * updateObject({payload, callback}: any, {call}: any) {
      const response = yield call(service.updateObject, payload);
      if (callback) {
        callback(response)
      }
    },
    * delete({payload, callback}: any, {call}: any) {
      const response = yield call(service.deleteOne, payload);
      if (callback) {
        callback(response)
      }
    }
  },
  reducers: {
    // save(state, action) {
    //   return {
    //     ...state,
    //     ...action.payload,
    //   };
    // },
    // 启用 immer 之后
    save(state, action) {
      state.name = action.payload;
    },
  },
  subscriptions: {
    setup({dispatch, history}) {
      return history.listen(({pathname}) => {
        if (pathname === '/') {
          dispatch({
            type: 'query',
          });
        }
      });
    },
  },
};

export default IndexModel;
